package org.example.platform.controller;

import org.springframework.web.bind.annotation.GetMapping;

@RestController
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 用户列表
     *
     * @return
     */
    @RequestMapping("/userList")
    public List<User> userList() {
        log.info("********TestController userList()");
        List<User> users = userService.selectList();
        return users;
    }

    /**
     * 保存用户
     *
     * @return
     */
    @GetMapping("/add")
    public Object add() {
        int num = 0;
        for (int i = 1; i <= 300; i++) {
            User user = new User();
            user.setId(i);
            user.setName("hzy" + (i));
            String sex = (i % 2 == 0) ? "男" : "女";
            user.setSex(sex);

            int resutl = userService.insert(user);
            log.info("insert:" + user.toString() + " result:" + resutl);
            num = num + resutl;
        }
        return num;
    }
}
